package jxl;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;

public class JSZCJxl {
    /** 开始行(行号) **/
	public static final int START_ROW=0;
	/** 开始列(列号) **/
	public static final int START_COLUMN=0;
	/** 字体大小 **/
	public static final int FONT_SIZE=12;
	/** 列宽 **/
	public static final int WIDTH=20;
	/** 行高**/
	public static final int HEIGHT=500;
	
	public static void main(String[] args) {
		WritableWorkbook book =null;
		WritableSheet sheet=null;
		try {
			book = Workbook.createWorkbook(new File("C:/test.xls"));
			sheet = book.createSheet("分包一", 0);
			//表格头部
			List<String> headerList=getHeaderList();
			JxlUtil.addTableHeader(sheet, START_COLUMN, START_ROW, 
					headerList, JxlUtil.getWCFormat(JxlUtil.getWFont(FONT_SIZE,true)),WIDTH,HEIGHT);
			//表格内容
			//1.合并单元格
			JxlUtil.mergeCells(sheet, START_COLUMN,START_ROW+1, START_COLUMN, START_ROW+getContentList().size());
			Label label=new Label(START_COLUMN,START_ROW+1,"供应商1",JxlUtil.getWCFormat(JxlUtil.getWFont(FONT_SIZE,false)));
			sheet.addCell(label);
			//2.添加内容
			JxlUtil.addTable(sheet, START_COLUMN+1, START_ROW+1, getStringList(), JxlUtil.getWCFormat(JxlUtil.getWFont(FONT_SIZE)));
			//JxlUtil.addTable(sheet, START_COLUMN+1, START_ROW+1, getContentList(), JxlUtil.getWCFormat(JxlUtil.getWFont(FONT_SIZE)), 
			//		"title1");
			book.write();
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			JxlUtil.closeQuietly(book);
		}
		
	}
	
	private static List<String> getHeaderList(){
		List<String> headerList=new ArrayList<String>();
		headerList.add("title1");headerList.add("title2");headerList.add("title3");
		headerList.add("title4");headerList.add("title5");headerList.add("title6");
		return headerList;
	}
	
	public static List<List<String>> getStringList(){
		List<List<String>> stringList=new ArrayList<List<String>>();
		List<String> string1=new ArrayList<String>();
		string1.add("a1");
		string1.add("b1");
		stringList.add(string1);
		List<String> string2=new ArrayList<String>();
		string2.add("a2");
		string2.add("b2");
		stringList.add(string2);
		List<String> string3=new ArrayList<String>();
		string3.add("a3");
		string3.add("b3");
		stringList.add(string3);
		return stringList;
		
	}
 	private static List<Person> getContentList(){
		List<Person> contentList=new ArrayList<Person>();
		Person person=new Person();
		person.setTitle1("a1");
		person.setTitle2("b1");
		person.setTitle3("c1");
		person.setTitle4("d1");
		person.setTitle5("e1");
		person.setTitle6("f1");
		contentList.add(person);
		person=new Person();
		person.setTitle1("a2");
		person.setTitle2("b2");
		person.setTitle3("c2");
		person.setTitle4("d2");
		person.setTitle5("e2");
		person.setTitle6("f2");
		contentList.add(person);
		person=new Person();
		person.setTitle1("a3");
		person.setTitle2("b3");
		person.setTitle3("c3");
		person.setTitle4("d3");
		person.setTitle5("e3");
		person.setTitle6("f3");
		contentList.add(person);
		return contentList;
		
	}
}
